import 'package:flutter/material.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/common/styles/colors.dart';

/// 频率调节项模型
class FrequencyAdjustmentItem {
  final String frequency;
  final String adjustmentTarget;
  final String userScenario;
  final String operationEffect;

  const FrequencyAdjustmentItem({
    required this.frequency,
    required this.adjustmentTarget,
    required this.userScenario,
    required this.operationEffect,
  });
}

class CustomDesView extends StatelessWidget {
  const CustomDesView({super.key});

  @override
  Widget build(BuildContext context) {
    return _buildFrequencyTable();
  }

  Widget _buildFrequencyTable() {
    final List<FrequencyAdjustmentItem> items = [
      const FrequencyAdjustmentItem(
        frequency: '250',
        adjustmentTarget: '控制"轰隆隆"低频噪声',
        userScenario: '地铁震动声太吵 → 拉低-6dB',
        operationEffect: '像给耳朵加"隔音地毯"',
      ),
      const FrequencyAdjustmentItem(
        frequency: '500',
        adjustmentTarget: '增强男声厚重感',
        userScenario: '爷爷说话含糊 → 拉高+4dB',
        operationEffect: '声音从"闷嗡"变"透亮"',
      ),
      const FrequencyAdjustmentItem(
        frequency: '1K',
        adjustmentTarget: '提升基础语音清晰度',
        userScenario: '电话听不清 → 拉高+5dB',
        operationEffect: '像调大手机通话音量',
      ),
      const FrequencyAdjustmentItem(
        frequency: '2K',
        adjustmentTarget: '突出女声和辅音细节',
        userScenario: '听不清"四"和"十"→ 拉高+6dB',
        operationEffect: '给语音加"高清滤镜"',
      ),
      const FrequencyAdjustmentItem(
        frequency: '3K',
        adjustmentTarget: '捕捉细微环境声',
        userScenario: '钥匙掉落听不到 → 拉高+3dB',
        operationEffect: '像开开"细节增强"模式',
      ),
      const FrequencyAdjustmentItem(
        frequency: '4K',
        adjustmentTarget: '抑制高频刺耳声',
        userScenario: '警报声难受 → 拉低-8dB',
        operationEffect: '给尖锐声包上"软布"',
      ),
      const FrequencyAdjustmentItem(
        frequency: '6K',
        adjustmentTarget: '调节金属/玻璃声攻击性',
        userScenario: '门铃声刺耳 → 拉低-5dB',
        operationEffect: '像磨钝刀片边缘',
      ),
    ];

    return Padding(
      padding: const EdgeInsets.only(left: 15.0, right: 10),
      child: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: Table(
          defaultColumnWidth: IntrinsicColumnWidth(),
          children: [
            _buildTableHeader(),
            ...items.map((item) => _buildTableRow(item)).toList(),
          ],
        ),
      ),
    );
  }

  TableRow _buildTableHeader() {
    return TableRow(
      children: [
        Padding(
          padding: EdgeInsets.all(8.0),
          child: Column(
            children: [
              Text(
                ' 频率',
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12.sp),
                textAlign: TextAlign.center,
              ),
              Text(
                '(Hz)',
                style: TextStyle(fontSize: 10.sp, color: Colours.text_gray),
                textAlign: TextAlign.center,
              ),
            ],
          ),
        ),
        Padding(
          padding: EdgeInsets.all(8.0),
          child: Text(
            '调节目标',
            style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12.sp),
            textAlign: TextAlign.center,
          ),
        ),
        Padding(
          padding: EdgeInsets.all(8.0),
          child: Text(
            '用户案例场景',
            style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12.sp),
            textAlign: TextAlign.center,
          ),
        ),
        Padding(
          padding: EdgeInsets.all(8.0),
          child: Text(
            '操作效果',
            style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12.sp),
            textAlign: TextAlign.center,
          ),
        ),
      ],
    );
  }

  TableRow _buildTableRow(FrequencyAdjustmentItem item) {
    return TableRow(
      children: [
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(
            item.frequency,
            textAlign: TextAlign.center,
            style: TextStyle(
              fontSize: 9.sp,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(
            item.adjustmentTarget,
            style: TextStyle(
              fontSize: 9.sp,
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(
            item.userScenario,
            style: TextStyle(
              fontSize: 9.sp,
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(
            item.operationEffect,
            style: TextStyle(
              fontSize: 9.sp,
            ),
          ),
        ),
      ],
    );
  }
}
